package com.rill.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.rill.po.User;

/**
dao实现类：继承HibernateDaoSupport，持有hibernateTemplate(需要spring管理)
 */
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

	@Override
	public void add(User user) {//使用继承的hibernateTemplate的属性的getter
		this.getHibernateTemplate().save(user);

	}

	@Override
	public void delete(User user) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(User user) {
		// TODO Auto-generated method stub

	}

	@Override
	public List queryAll() {
		List list = this.getHibernateTemplate().find("select * from User");
		return list;
	}

	@Override
	public User queryByID(String username) {
		List list = this.getHibernateTemplate().find("select user from User user where user.username = '" + username + "'");
		if(list.size() == 0) {
			return null;
		} else {
			return (User)list.get(0);
		}
	}

}
